<?php
declare (strict_types = 1);

namespace app\admin\controller;

use think\facade\Db;
use think\facade\View;
use think\facade\Request;

class goods
{
    public function good_add()
    {
        return View::fetch();
    }
    public function good_list()
    {
        $where='1=1';
        $ishow=Request::get('if_show');
        $recommended=Request::get('recommended');
        $open = Request::get('if_open');
        $keywords = Request::get('keywords');
        $cid = Request::get('cate_id');
        if($ishow!=""){
            $where.=" and if_show={$ishow}";
        }
        if($recommended!=""){
            $where.=" and recommended={$recommended}";
        }
        if($open!=""){
            $where.=" and if_open={$open}";
        }
        if($keywords!=""){
            $where.=" and goods_name like '%{$keywords}%'";
        }
        if($cid!=""){
            $where.=" and cate_id={$cid}";
        }

        $tname=Request::get('tname');
        if ($tname=='上架时间'){
            $tname='上架升序↑';
            $order='add_time asc';
        }elseif($tname=='上架升序↑'){
            $tname='上架降序↓';
            $order='add_time desc';
        }else{
            $tname='上架时间';
            $order='add_time';
        }
        $rt=Db::table('ecm_goods')
            ->where($where)
            ->order($order)
            ->select();
        View::assign('list',$rt);
        View::assign('timer',$tname);
        View::assign('ishow',$ishow);
        View::assign('order',$order);
        View::assign('recommended',$recommended);
        View::assign('open',$open);
        View::assign('keywords',$keywords);
        View::assign('cid',$cid);
        return  View::fetch();
    }
}

